package com.bdzl.biz.controller;

import com.bdzl.biz.service.OdrFileCategoryService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.OdrFileCategoryDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import com.bdzl.pub.vo.loan.OdrFileCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 融资租赁订单合同权证类别表，主要记录订单相关附件（主要指合同与权证资料）的分类信息。
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:02:10
 */

@Controller
@RequestMapping("/bdzl/odrFileCategory")
public class OdrFileCategoryController extends BaseController {
	@Autowired
	private OdrFileCategoryService odrFileCategoryService;

	@GetMapping()
	String OdrFileCategory(){
	    return "bdzl/odrFileCategory/odrFileCategory";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OdrFileCategoryDO> odrFileCategoryList = odrFileCategoryService.list(query);
		int total = odrFileCategoryService.count(query);
		PageUtils pageUtils = new PageUtils(odrFileCategoryList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/odrFileCategory/add";
	}

	@GetMapping("/edit/{catId}")
	R edit(@PathVariable("catId") Integer catId){
		OdrFileCategoryDO odrFileCategory = odrFileCategoryService.get(catId);
	    return R.ok(odrFileCategory);
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody @Validated OdrFileCategoryDO odrFileCategory){
		odrFileCategory.setCatCreuser(super.getUserId());
		if(odrFileCategoryService.save(odrFileCategory)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody @Validated  OdrFileCategoryDO odrFileCategory){
		odrFileCategory.setCatModuser(super.getUserId());
		odrFileCategory.setCatModtime(new Date());
		odrFileCategoryService.update(odrFileCategory);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestParam("catId") Integer catId){
		if(odrFileCategoryService.remove(catId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] catIds){
		odrFileCategoryService.batchRemove(catIds);
		return R.ok();
	}

	/**
	 * 查询
	 */
	@GetMapping("/{catId}")
	@ResponseBody
	public R get(@PathVariable("catId") Integer catId){
		OdrFileCategoryVO odrFileCategory = odrFileCategoryService.getAll(catId);
		return R.ok(odrFileCategory);
	}


	@ResponseBody
	@GetMapping("/listAll")
	public PageUtils listAll(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<OdrFileCategoryVO> odrFileCategoryList = odrFileCategoryService.listAll(query);
		int total = odrFileCategoryService.listAllcount(query);
		PageUtils pageUtils = new PageUtils(odrFileCategoryList, total);
		return pageUtils;
	}

}
